package logic

import (
	"context"
	"fmt"
	"srv/model/redis"

	"srv/cart"
	"srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StateCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStateCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StateCartLogic {
	return &StateCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StateCartLogic) StateCart(in *cart.StateCartRequest) (*cart.StateCartResponse, error) {
	// todo: add your logic here and delete this line
	err := redis.StateCart(in.UserId, in.State)
	if err != nil {
		logx.Error("状态修改失败")
		return nil, fmt.Errorf("状态修改失败")
	}
	return &cart.StateCartResponse{State: in.State}, nil
}
